package com.stylefeng.guns.biz.singlePage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.singlePage.model.TSinglePage;
import com.stylefeng.guns.biz.singlePage.service.ITSinglePageService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 单页面控制器
 *
 * @author fengshuonan
 * @Date 2018-06-14 06:34:48
 */
@Controller
@RequestMapping("/tSinglePage")
public class TSinglePageController extends BaseController {

    private String PREFIX = "/app/tSinglePage/";

    @Autowired
    private ITSinglePageService tSinglePageService;

    /**
     * 跳转到单页面首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tSinglePage.html";
    }

    /**
     * 跳转到添加单页面
     */
    @RequestMapping("/tSinglePage_add")
    public String tSinglePageAdd() {
        return PREFIX + "tSinglePage_add.html";
    }

    /**
     * 跳转到修改单页面
     */
    @RequestMapping("/tSinglePage_update/{tSinglePageId}")
    public String tSinglePageUpdate(@PathVariable Long tSinglePageId, Model model) {
        TSinglePage tSinglePage = tSinglePageService.selectById(tSinglePageId);
        model.addAttribute("item",tSinglePage);
        LogObjectHolder.me().set(tSinglePage);
        return PREFIX + "tSinglePage_edit.html";
    }

    /**
     * 获取单页面列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	EntityWrapper<TSinglePage> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id_key", appid);
        return tSinglePageService.selectList(wrapper);
    }

    /**
     * 新增单页面
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TSinglePage tSinglePage) {
        tSinglePageService.insert(tSinglePage);
        return SUCCESS_TIP;
    }

    /**
     * 删除单页面
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long tSinglePageId) {
        tSinglePageService.deleteById(tSinglePageId);
        return SUCCESS_TIP;
    }

    /**
     * 修改单页面
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TSinglePage tSinglePage) {
        tSinglePageService.updateById(tSinglePage);
        return SUCCESS_TIP;
    }

    /**
     * 单页面详情
     */
    @RequestMapping(value = "/detail/{tSinglePageId}")
    @ResponseBody
    public Object detail(@PathVariable("tSinglePageId") Long tSinglePageId) {
        return tSinglePageService.selectById(tSinglePageId);
    }
}
